package com.homedo.odin.solution.service.common.impl;

import com.homedo.core.common.util.HttpClient;
import com.homedo.odin.solution.config.WalletConfigHelper;
import com.homedo.odin.solution.service.common.WalletService;
import java.util.Map;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

/**
 * @author: zhaoxudong
 * @date: 2018/4/11 17:16
 * @Description:
 */
@Service
public class WalletServiceImpl implements WalletService {

    private static final Logger log = LoggerFactory.getLogger(WalletServiceImpl.class);

    @Autowired
    WalletConfigHelper walletConfig;

    /**
     * 充值打款
     */
    @Override
    public String addWalletBalance(Map<String, String> paramMap) {
        /***服务方的增加收到的服务费*/
		/*map.put("accountId", projectBaisc.getAcceptor()+"");
		map.put("walletType", "1");
		map.put("amount", applyPayment.getApplyAmount().toString());
		map.put("bizFrom", "");
		map.put("bizOrderCode", applyPayment.getApplyId());
		map.put("inOut", "1");
		map.put("payType", "3");
		map.put("note", projectBaisc.getName());*/
        String returnJson = "";
        MultiValueMap<String, String> map = getMultiValueMap(paramMap);
        try {
            returnJson = HttpClient.post(walletConfig.getAddBalance(), map);
            log.info(returnJson);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
        return returnJson;
    }

    private MultiValueMap<String, String> getMultiValueMap(Map<String, String> paramMap) {
        MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
        if (paramMap != null && !paramMap.isEmpty()) {
            Set<String> keySet = paramMap.keySet();
            for (String key : keySet) {
                map.add(key, paramMap.get(key));
            }
        }

        return map;
    }
}
